package com.fanco.learn_datastruct_leetcode.leetcode;

import java.util.*;

/**
 * @author qiaowang 2021/7/6
 */
public class Day14 {
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.generateParenthesis(1));
    }

    private static class Solution {
        public List<String> generateParenthesis(int n) {
            if (n == 1) {
                return Arrays.asList("()");
            }
            Set<String> hs = new HashSet<>();
            for (String s : generateParenthesis(n-1)) {
                for (int i = 0; i < 2*n-2; i++) {
                    hs.add(s.substring(0,i) + "()" + s.substring(i,s.length()));
                }
            }
            return new ArrayList(hs);
        }

    }
}
